package com.lh.music.util;

import android.content.Context;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.lh.music.callback.CallBack;

/**
 * Created by a on 2016/12/14.
 */

public class RequestUtil {
    private Context context;
    private RequestQueue queue;
    private CallBack callBack;
    public RequestUtil(Context context,CallBack callBack) {
        this.context = context;
        queue= Volley.newRequestQueue(context);
        this.callBack=callBack;
    }
    /**
     * 获得排行的内容
     */
    public void getPaihangContent(String path){
        StringRequest request=new StringRequest(Request.Method.GET,
                path,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        callBack.callBack(response);
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        callBack.errorCallBack();
                        Toast.makeText(context, "请检查你的网络连接", Toast.LENGTH_SHORT).show();

                    }
                });
        queue.add(request);
    }
}
